/*
 * @Author: moxunjingmu
 * @Date: 2025-03-09 16:23:33
 * @Description: 
 */
import { useEffect } from 'react';
import { useColorScheme } from 'react-native';
import { useAppStore } from '@/store/app-store';
import Colors from '@/constants/colors';
import { useContext, useCallback } from 'react';
import { ThemeContext } from '@/contexts/ThemeContext';
import { StyleSheet, TextStyle, ViewStyle, ImageStyle } from 'react-native';

type NamedStyles<T> = { [P in keyof T]: ViewStyle | TextStyle | ImageStyle };

export const useTheme = () => {
  const context = useContext(ThemeContext);
  
  if (context === undefined) {
    throw new Error('useTheme must be used within a ThemeProvider');
  }
  
  // 创建一个函数来生成主题化的样式
  const createThemedStyles = useCallback(<T extends NamedStyles<T>>(
    styleCreator: (colors: typeof context.colors) => T
  ): T => {
    return StyleSheet.create(styleCreator(context.colors));
  }, [context.colors]);
  
  return {
    ...context,
    createThemedStyles,
  };
};